import { useDesignSettingStore } from '@/store/modules/designSetting';
import * as NaiveUI from 'naive-ui';
import { App, computed } from 'vue';
import  store from '@/store';

// NaiveUI 全局方法注册
const designStore = useDesignSettingStore(store)
const configProviderPropsRef = computed(() => ({
  theme: designStore.darkTheme ? NaiveUI.darkTheme : undefined,
}));

const { message, dialog, notification, loadingBar } = NaiveUI.createDiscreteApi(
  ['message', 'dialog', 'notification', 'loadingBar'],
  {
    configProviderProps: configProviderPropsRef,
  }
);
window['$message'] = message;
window['$dialog'] = dialog;
window['$notification'] = notification;
window['$loading'] = loadingBar;

const naive = NaiveUI.create({
  components: [
    NaiveUI.NMessageProvider,
    NaiveUI.NDialogProvider,
    NaiveUI.NConfigProvider,
  ]
})

export function setupNaive(app: App) {
  app.use(naive)
}